package ${package.Controller};

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import com.wjc.train.${moduleName}.req.${entity}QueryReq;
import com.wjc.train.${moduleName}.resp.${entity}QueryResp;
import org.springframework.web.bind.annotation.*;
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
@Validated
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Resource
    private ${table.serviceName} ${lowerEntity}Service;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid ${entity}SaveReq ${lowerEntity}SaveReq){
        ${lowerEntity}Service.save(${lowerEntity}SaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp save(@RequestBody ${entity}QueryReq ${lowerEntity}QueryReq){
        IPage<${entity}QueryResp> iPage =
        ${lowerEntity}Service.queryList(PageUtil.getPage(${lowerEntity}QueryReq.getQueryPage()), ${lowerEntity}QueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        ${lowerEntity}Service.delete(id);
        return CommonResp.success();
    }


}
</#if>


